package com.dq.Week1.day04.homeWork;

import java.util.Scanner;

//1221
//1221 % 10 = 1
//122 % 10 = 2
//12 % 10 = 2
//1 % 10 = 1
public class recycleNumber {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个数字：");
        int number = scanner.nextInt();
        if (isPalindrome(number)) {
            System.out.println("是回文数");
        } else {
            System.out.println("不是回文数，请重新输入");
        }

    }

    public static boolean isPalindrome(int number) {
        int temp = number;//存数据
        int revers = 0;//存取位数实现逆转数字
        while (number != 0) {
            int num = number % 10;//取出最小位 例：121   取出1     第二层循环就取出 2
            revers = (revers * 10) + num;//  乘10是为了让上一次取出的位数进一位 如121 取出1 后  下一次循环就是 10+2
            number /= 10;     //提取除了个位以外的位数
        }
        if (revers == temp) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isPalindrome2(int number)
    {
        String str = String.valueOf(number);
        char[] arr = str.toCharArray();

        int left = 0;
        int right = arr.length-1;

        while (left < right)
        {
            if (arr[left] != arr[right])
            {
                return false;
            }
            left++;
            right--;

        }
        return true;
    }
}
